home *** CD-ROM | disk | FTP | other *** search
- /**
- ** IconifyClass testen, Holgi am 31.07.94 mit MaxonC
- ** benötigt OS2.0+
- **
- ** Tabsize = 3
- **/
-
- #include <exec/types.h>
- #include <pragma/dos_lib.h>
- #include <pragma/exec_lib.h>
- #include <pragma/icon_lib.h>
- #include <pragma/intuition_lib.h>
- #include <pragma/wb_lib.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/imageclass.h>
- #include <workbench/startup.h>
-
- #include "IconifyClass.h"
-
- #define ICON_WIDTH (26)
- #define ICON_ID (1000)
-
- void Test();
- BOOL OpenWin();
- void CloseWin();
- BOOL AddIcon();
- void RemoveIcon();
-
- STRPTR ProgName;
- struct Library *IntuitionBase;
- struct Library *GfxBase;
- struct Library *IconBase;
- struct Library *WorkbenchBase;
- struct IClass *IconifyClass;
-
- struct Screen *MyScr = NULL;
- Object *MyIcon = NULL;
- Object *MyIconGG = NULL;
- struct Window *MyWin = NULL;
- struct MsgPort *IconPort = NULL;
- struct DiskObject *ProgIcon = NULL;
- struct AppIcon *AppIcon = NULL;
-
- void wbmain( struct WBStartup *ws )
- {
- CurrentDir( ws->sm_ArgList->wa_Lock );
- ProgName = ws->sm_ArgList->wa_Name;
- Test();
- }
-
- main()
- {
- BPTR OldLock, ProgLock;
- UBYTE NameBuf[ 32 ];
-
- if( ProgLock = Lock( "PROGDIR:", ACCESS_READ ))
- {
- OldLock = CurrentDir( ProgLock );
- if( GetProgramName( NameBuf, sizeof( NameBuf )))
- {
- ProgName = NameBuf;
- Test();
- }
- CurrentDir( OldLock );
- UnLock( ProgLock );
- }
- }
-
- void Test()
- {
- if( IntuitionBase = OpenLibrary( "intuition.library", 36 ))
- {
- if( GfxBase = OpenLibrary( "graphics.library", 36 ))
- {
- if( IconBase = OpenLibrary( "icon.library", 36 ))
- {
- if( WorkbenchBase = OpenLibrary( "workbench.library", 36 ))
- {
- if( IconifyClass = InitIconify( IntuitionBase, GfxBase ))
- {
- if( OpenWin())
- {
- BOOL Finished = FALSE,
- Iconified = FALSE;
-
- while( !Finished )
- {
- if( Iconified )
- {
- WaitPort( IconPort );
- RemoveIcon();
- Finished = !OpenWin();
- Iconified = FALSE;
- }
- else
- {
- struct IntuiMessage *IMsg;
- struct Gadget *MsgObj;
- ULONG MsgClass;
-
- WaitPort( MyWin->UserPort );
- while( !Finished && (IMsg = (struct IntuiMessage *)
- GetMsg( MyWin->UserPort )))
- {
- MsgClass = IMsg->Class;
- MsgObj = (struct Gadget *) IMsg->IAddress;
- ReplyMsg( (struct Message *) IMsg );
-
- switch( MsgClass )
- {
- case IDCMP_CLOSEWINDOW:
- Finished = TRUE;
- break;
-
- case IDCMP_GADGETUP:
- if( MsgObj->GadgetID == ICON_ID )
- {
- CloseWin();
- Finished = !AddIcon();
- Iconified = TRUE;
- }
- default:
- break;
- }
- }
- }
- }
- }
- RemoveIcon();
- CloseWin();
- RemoveIconify( IconifyClass );
- }
- CloseLibrary( WorkbenchBase );
- }
- CloseLibrary( IconBase );
- }
- CloseLibrary( GfxBase );
- }
- CloseLibrary( IntuitionBase );
- }
- }
-
- BOOL OpenWin()
- {
- if( MyScr = LockPubScreen( NULL ))
- {
- struct TagItem IconTags[] = {
- IA_Left,0, IA_Top,0, IA_Width,ICON_WIDTH,
- IA_Height,MyScr->BarHeight + 1, TAG_DONE,0
- };
- if( MyIcon = NewObjectA( IconifyClass, NULL, IconTags ))
- {
- struct TagItem IconGGTags[] = {
- GA_RelRight,-70, GA_Top,0, GA_Width,ICON_WIDTH,
- GA_Height,MyScr->BarHeight + 1, GA_Image,(ULONG) MyIcon,
- GA_RelVerify,TRUE, GA_ID,ICON_ID, TAG_DONE,0
- };
- if( MyIconGG = NewObjectA( NULL, BUTTONGCLASS, IconGGTags ))
- {
- struct TagItem WinTags[] = {
- WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
- WA_Title,(ULONG) "IconifyClass Test",
- WA_MinWidth,70 + 18 + ICON_WIDTH,
- WA_MinHeight,MyScr->BarHeight + 11, WA_MaxWidth,~0,
- WA_MaxHeight,~0, WA_SizeGadget,TRUE, WA_DragBar,TRUE,
- WA_DepthGadget,TRUE, WA_CloseGadget,TRUE,
- WA_NoCareRefresh,TRUE, WA_Activate,TRUE, WA_RMBTrap,TRUE,
- WA_SmartRefresh,TRUE, WA_AutoAdjust,TRUE, WA_InnerWidth,400,
- WA_InnerHeight,100, WA_PubScreen,(ULONG) MyScr, TAG_DONE,0
- };
- if( MyWin = OpenWindowTagList( NULL, WinTags ))
- {
- AddGadget( MyWin, (struct Gadget *) MyIconGG, 0 );
- RefreshGList( (struct Gadget *) MyIconGG, MyWin, NULL, 1 );
- }
- }
- }
- }
- return( MyWin != NULL );
- }
-
- void CloseWin()
- {
- if( MyWin ) { CloseWindow( MyWin ); MyWin = NULL; }
- if( MyIconGG ) { DisposeObject( MyIconGG ); MyIconGG = NULL; }
- if( MyIcon ) { DisposeObject( MyIcon ); MyIcon = NULL; }
- if( MyScr ) { UnlockPubScreen( NULL, MyScr ); MyScr = NULL; }
- }
-
- BOOL AddIcon()
- {
- STRPTR ProgName = "Test";
-
- if( IconPort = CreateMsgPort())
- {
- if( ProgIcon = GetDiskObjectNew( ProgName ))
- {
- ProgIcon->do_CurrentX = ProgIcon->do_CurrentY = NO_ICON_POSITION;
- AppIcon = AddAppIconA( 0, 0, ProgName, IconPort, NULL, ProgIcon, NULL );
- }
- }
- return( AppIcon != NULL );
- }
-
- void RemoveIcon()
- {
- if( AppIcon ) { RemoveAppIcon( AppIcon ); AppIcon = NULL; }
- if( ProgIcon ) { FreeDiskObject( ProgIcon ); ProgIcon = NULL; }
- if( IconPort )
- {
- struct Message *Msg;
- while( Msg = GetMsg( IconPort )) ReplyMsg( Msg );
- DeleteMsgPort( IconPort );
- IconPort = NULL;
- }
- }
-